package myPackage;

import java.io.File;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;


public class GameReader {

	public static void main(String args[]) {

		
		NodeList root = null;
		Node quiz = null;
		
		
		try {

			Document xml = new XMLProcessor(new File(Paths.getScoreSheet() + "/68.xml")).XMLReader();
			root = xml.getElementsByTagName("scoresheet");

			for (int i = 0; i <= root.getLength(); i++) {

				quiz = root.item(i);
				System.out.println(quiz.getNodeName());

				
			}

			DOMSource XMLinput = new DOMSource(xml);
			StreamResult XMLoutput = new StreamResult(Paths.getUsers());
			new XMLProcessor().getTransformer().transform(XMLinput, XMLoutput);

		} catch (NullPointerException e) {
			System.err.println("User doesn't exist!");
		} catch (TransformerConfigurationException e) {
			System.err.println(e);
		} catch (TransformerException e) {
			System.err.println(e);
		}
	
		
		//TODO setLastLevel(int LastLevel, Date today)
//		Date today = new Date();
//		DateFormat date = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss");
//		XMLProcessor x = new XMLProcessor(new File(Paths.getScoreSheet() + "/68.xml"));
//		Node quiz = x.XMLReader().getElementsByTagName("quiz").item(0);
//		
//		NamedNodeMap attr = quiz.getAttributes();
//		Integer id = Integer.valueOf(attr.getNamedItem("id").getTextContent().toString());
//		id++;
//		System.out.println(id);
//		Node nodeAttr = attr.getNamedItem("id");
//		nodeAttr.setTextContent(String.valueOf(id++));
		
	}
}